package cn.driver.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.driver.domain.Student;
import cn.driver.domain.Teacher;
import cn.driver.service.TeacherService;
import cn.driver.utils.MyException;
@RestController
@RequestMapping("/teacher")
public class TeacherController {
	@Autowired
	private TeacherService teacherService;
	
	//添加学员
	@RequestMapping("/regist")
	public Map<Object,Object> regist(String name,String id,String phone,Integer age,String gender){
		Map<Object,Object> map = new HashMap<Object,Object>();
		try{
			
			teacherService.regist( name,id, phone, age, gender);
				map.put("success", true);
			
		}catch (MyException e) {
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}catch(Exception e){
			e.printStackTrace();
		}
		return map;
	}
	
	//遍历学员信息
	@RequestMapping("/list")
	public List<Teacher> studentInfo(){
		return teacherService.studentInfo();
	}
	
	//遍历学员信息
	@RequestMapping("/search")
	public List<Teacher> stuSearch(String Info){
		return teacherService.stuSearch(Info);
	}
	//删除学员
	@RequestMapping("/delete")
	public Map<Object,Object> deleteStu(String id){
		Map<Object,Object> map = new HashMap<Object,Object>();
		try{
			
			teacherService.deleteStu(id);
				map.put("success", true);
			
		}catch (MyException e) {
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}
		return map;
	}
	//查找单个学员信息
	@RequestMapping("/selectInfo")
	public Teacher selectInfo(String id){
		return teacherService.selectStudent(id);
	}
	//修改学员信息
	@RequestMapping("/update")
	public Map<Object,Object> updateStu(
			
			String info,String name,String id,String phone,Integer age,String gender	){
		Map<Object,Object> map = new HashMap<Object,Object>();
		try{
			
			teacherService.updateStu(info,name,id, phone, age, gender);
				map.put("success", true);
			
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}
		return map;
	}
}
